package com.binbinyl.helper.network

import com.binbinyl.helper.Util
import okhttp3.Interceptor
import okhttp3.Response

class NetInterceptor(private val requestHandler: RequestHandler) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()

        if (!Util.checkNull(requestHandler)) {
            requestHandler.beforeRequest(request,chain)
        }

        val response = chain.proceed(request)

        if (!Util.checkNull(requestHandler)) {
            val temp = requestHandler.afterRequest(response,chain)

            if (!Util.checkNull(temp)){
                return temp
            }
        }
        return response
    }
}